
/**
  ******************************************************************************
  * @file    Lcd.h
  * @author  Dajin Li
  * @version V0.0.1
  * @date    08-08-2015 
  * @brief   This file contains Dislpay LCD function
  *				 
  *          
  ******************************************************************************
  * @attention
  *
  * <h2><center>&copy; KION(SZ) R&D Center
  *
  * Licensed under KION, (the "License");
  *
  ******************************************************************************
  */


#ifndef __LCD_H__
#define __LCD_H__
/* Includes ------------------------------------------------------------------*/

#include "stm32f10x.h"
#include "global.h"




#ifdef  S1D19600 

//S1D19600D spec


#define END_PAGE                                   159

#define LCD_WIDTH                                  0xF0                                                    // 240
#define LCD_HEIGHT                                 0x140                                                   // 320
                                                                                                           
#define ROWMAX		                               0x140		                                           // 320 - S1D19600D number of LCD pixel rows 0-239 
#define COLMAX		                               0xF0		                                               // 240 - S1D19600D number of LCD pixel columns 0-319 
#define COLMAXMON		                           (COLMAX)	                                               // 240 - number of 3-pixel column sets in monochrome mode 
#define ROWMAXMON		                           (ROWMAX/2)	                                           // 160 - number of 2-pixel in 4 bpp mode 
#define LCDCMD		                               0x01		                                               // tells the calling routine that the info passed is a command
#define LCDDATA		                               0x00		                                               // tells the calling routine that the info passed is data

#define SW_RST                                     0x5E
#define DISAR                                      0x91
#define DISSET1                                    0x92
#define DISSET2                                    0x93
#define MADCTL                                     0x21
#define STFRAME                                    0x24
#define BPPSEL                                     0x25
#define MDCTL                                      0x26
#define GATSET                                     0xA2
#define BPPSET                                     0x86
#define BPPSET2P                                   0x85
#define BPPSET2N                                   0x8D
#define GAMSET4P1                                  0x81
#define GAMSET4P2                                  0x82
#define GAMSET4P3                                  0x83
#define GAMSET4P4                                  0x84
#define GAMSET4N1                                  0x89
#define GAMSET4N2                                  0x8A
#define GAMSET4N3                                  0x8B
#define GAMSET4N4                                  0x8C

#define ACSET                                      0xA1

#define ONE_LINE_INV_DRIVE                         0
#define TWO_LINE_INV_DRIVE                         0x11
#define FRAME_INV_DRIVE                            0x22
#define INTERLACE_DRIVE                            0x33

#define EVSET1                                     0x71
#define EVSET2                                     0x72
#define PWRCTL                                     0x61
#define VCMDAT                                     0x49

#define SLPOUT                                     0x13

#define CASET                                      0x23
#define PASET                                      0x22
                                                   
#define DISON                                      0x12
#define DISOFF                                     0x11

#define WRRAM                                      0x3A

#define ONE_BPP_MODE_END_PAGE                      39
#define TWO_BPP_MODE_END_PAGE                      79
#define FOUR_BPP_MODE_END_PAGE_LESS_160            79
#define FOUR_BPP_MODE_END_PAGE_OVER_160            159

#define COLUMN_ADDR_NOM                            0x00   // S1:Addr0, S320:S319
#define COLUMN_ADDR_REV                            0x01   // S1:Addr319, S320:Addr0

#define PAGE_ADDR_NOM                              0x00   // L1: line 0, L320: line319
#define PAGE_ADDR_REV                              0x02   // L1: line 319, L320: line 0
              
#define INC_COL_ADDR_DIR                           0x00   // 
#define INC_PAGE_ADDR_DIR                          0x04   // 

#define SCAN_MODE_USING                            SCAN_MODE_0

#define SCAN_MODE_0                                0x00   // horizontal scan, column(left-right), row(top-down)
#define SCAN_MODE_1                                0x01   // horizontal scan, column address reverse, column(right-left),row(top-down)  
#define SCAN_MODE_2                                0x02   // horizontal scan, page address reverse, column(left-right), row(down-top)
#define SCAN_MODE_3                                0x03   // horizontal scan, page address reverse, column address reverse,column(left-right),row(down_top)  

#define SCAN_MODE_4                                0x04   // vertical scan,column(left-right), row(top-down) 
#define SCAN_MODE_5                                0x05   // vertical scan, column address reverse, column(right-left),row(top-down)   
#define SCAN_MODE_6                                0x06   // vertical scan, page address reverse, column(left-right), row(down-top)
#define SCAN_MODE_7                                0x07   // vertical scan, page address reverse, column address reverse, column address reverse,column(left-right),row(down_top)   

#define GRAYSCALE_2                                0
#define GRAYSCALE_4                                1
#define GRAYSCALE_16                               2
                                                   
// Set line scan mode

#define INTERLACE_DRIVER_1                         0
#define INTERLACE_DRIVER_2                         1
#define UP_DOWN_DRIVER_1                           2
#define UP_DOWN_DRIVER_2                           3

#define CHR5HEIGHT	                               0x07		// 5x7 character height 
#define CHR5WIDTH	                               0x05		// 5x7 character width 

#define CHR5VSP		                               0x03		//5x7 vertical character spacing between character rows 
#define CHR5HSP		                               0x01		//5x7 horizontal character spacing between characters 


#define CHR9HEIGHT	                               0x0e		//9x14 character height 
#define CHR9WIDTH	                               0x09	    //9x14 character width 
#define CHR9VSP		                               0x03		//9x14 vertical character spacing between character rows 
#define CHR9HSP		                               0x01		//9x14 horizontal character spacing between characters 
#define CHR9VLIN		                           (CHR9HEIGHT + CHR9VSP)

#define CHR8HEIGHT	                               0x0c		//8x12 character height 
#define CHR8WIDTH	                               0x08		//8x12 character width 
#define CHR8VSP		                               0x00		//8x12 vertical character spacing between character rows 
#define CHR8HSP		                               0x01		//8x12 horizontal character spacing between characters 
#define CHR8VLIN		                           (CHR8HEIGHT + CHR8VSP)

#define DELAY_1MS                                  1
#define DELAY_2MS                                  2


#define BK_HI                                      0x0F
#define BK_LOW                                     0xF0

#endif


#ifdef  ST7511 

//S1D19600D spec
#define END_PAGE                                   159
#define LCD_WIDTH                                  240                                                    // 240
#define LCD_HEIGHT                                 320                                                   // 320
                                                                                                           
#define ROWMAX		                               320		                                           // 320 - S1D19600D number of LCD pixel rows 0-239 
#define COLMAX		                               240		                                               // 240 - S1D19600D number of LCD pixel columns 0-319 
#define COLMAXMON		                           (COLMAX)	                                               // 240 - number of 3-pixel column sets in monochrome mode 
#define ROWMAXMON		                           (ROWMAX/2)	                                           // 160 - number of 2-pixel in 4 bpp mode 
#define LCDCMD		                               0x01		                                               // tells the calling routine that the info passed is a command
#define LCDDATA		                               0x00		                                               // tells the calling routine that the info passed is data

#define PWRCTL                                     0x61 
#define EVSET1                                     0x62                                                    // Electronic Volumn Set 1
#define DISAR                                      0x31                                                    // Display area
#define DISSET1                                    0x32                                                    // Display area
#define DISSET2                                    0x33                                                    // Display area
#define EVSET2                                     0x63                                                    // Electronic Volumn Set 2
#define GAMSET4P1                                  0x91
#define GAMSET4P2                                  0x92
#define GAMSET4P3                                  0x93
#define GAMSET4P4                                  0x94

#define GAMSET4N1                                  0x99
#define GAMSET4N2                                  0x9A
#define GAMSET4N3                                  0x9B
#define GAMSET4N4                                  0x9C

#define SLPOUT                                     0x12
#define DINVIN                                     0x1B
#define DINVOUT                                    0x1A
#define MADCTL                                     0x24
#define BPPSEL                                     0x22

#define DISON                                      0x15
#define WRRAM                                      0x2C

#define CASET                                      0x26
#define PASET                                      0x25


#define ONE_BPP_MODE_END_PAGE                      39
#define TWO_BPP_MODE_END_PAGE                      79
#define FOUR_BPP_MODE_END_PAGE_LESS_160            79
#define FOUR_BPP_MODE_END_PAGE_OVER_160            159

#define COLUMN_ADDR_NOM                            0x00   // S1:Addr0, S320:S319
#define COLUMN_ADDR_REV                            0x01   // S1:Addr319, S320:Addr0

#define PAGE_ADDR_NOM                              0x00   // L1: line 0, L320: line319
#define PAGE_ADDR_REV                              0x02   // L1: line 319, L320: line 0
              
#define INC_COL_ADDR_DIR                           0x00   // 
#define INC_PAGE_ADDR_DIR                          0x04   // 

#define SCAN_MODE_USING                            SCAN_MODE_0

#define SCAN_MODE_0                                0x00   // horizontal scan, column(left-right), row(top-down)
#define SCAN_MODE_1                                0x01   // horizontal scan, column address reverse, column(right-left),row(top-down)  
#define SCAN_MODE_2                                0x02   // horizontal scan, page address reverse, column(left-right), row(down-top)
#define SCAN_MODE_3                                0x03   // horizontal scan, page address reverse, column address reverse,column(left-right),row(down_top)  

#define SCAN_MODE_4                                0x04   // vertical scan,column(left-right), row(top-down) 
#define SCAN_MODE_5                                0x05   // vertical scan, column address reverse, column(right-left),row(top-down)   
#define SCAN_MODE_6                                0x06   // vertical scan, page address reverse, column(left-right), row(down-top)
#define SCAN_MODE_7                                0x07   // vertical scan, page address reverse, column address reverse, column address reverse,column(left-right),row(down_top)   

#define GRAYSCALE_2                                0
#define GRAYSCALE_4                                1
#define GRAYSCALE_16                               2
                                                   
// Set line scan mode

#define INTERLACE_DRIVER_1                         0
#define INTERLACE_DRIVER_2                         1
#define UP_DOWN_DRIVER_1                           2
#define UP_DOWN_DRIVER_2                           3

#define CHR5HEIGHT	                               0x07		// 5x7 character height 
#define CHR5WIDTH	                               0x05		// 5x7 character width 

#define CHR5VSP		                               0x03		//5x7 vertical character spacing between character rows 
#define CHR5HSP		                               0x01		//5x7 horizontal character spacing between characters 


#define CHR9HEIGHT	                               0x0e		//9x14 character height 
#define CHR9WIDTH	                               0x09	    //9x14 character width 
#define CHR9VSP		                               0x03		//9x14 vertical character spacing between character rows 
#define CHR9HSP		                               0x01		//9x14 horizontal character spacing between characters 
#define CHR9VLIN		                           (CHR9HEIGHT + CHR9VSP)

#define CHR8HEIGHT	                               0x0c		//8x12 character height 
#define CHR8WIDTH	                               0x08		//8x12 character width 
#define CHR8VSP		                               0x00		//8x12 vertical character spacing between character rows 
#define CHR8HSP		                               0x01		//8x12 horizontal character spacing between characters 
#define CHR8VLIN		                           (CHR8HEIGHT + CHR8VSP)

#define DELAY_1MS                                  1
#define DELAY_2MS                                  2


#define BK_HI                                      0x0F
#define BK_LOW                                     0xF0

#endif

extern u8 OLED_GRAM[8][128];

extern void LCD_init(void);
extern void test_pattern(u8 pattern);
extern void LCD_wr_line(s16 row,s16 column,s16 length,u8 type,u8 color);
extern void lcd_memory_addr_control(u8 cmd);
extern void LCD_hw_clear(u16 row, u16 column, u16 height,u16 width, u8 gray);
extern void LCD_draw_line(u16 row, u16 column, u16 height,u16 width, u8 invert, u8 gray);
extern void LCD_clear_zone(u16 start_col, u16 end_col);
extern void LCD_wr_icon(s16 row, s16 column, s16 width, s16 height, u8 invert, u8 *str, u8 gray);
extern void LCD_wr_icon_gray(s16 row, s16 column, s16 width, s16 height, u8 invert, u8 *str, u8 gray);
extern void LCD_wr_icon_gray_special(s16 row, s16 column, s16 width, s16 height, u8 invert, u8 *str, u8 gray);
extern void LCD_wr_icon_gray_zone(s16 row, s16 column, s16 width, u8 invert, u8 *str, u8 gray, u16 start_col, u16 end_col);
extern void LCD_wr_zone(s16 row, s16 column, s16 width, s16 height, u8 gray);
extern void clear_status_menu_zone(void);
extern void LCD_wr_Data(u8 data);
extern void lcd_column_set(s16 column);
extern void lcd_page_addr_set(s16 page);
extern void LCD_wr_Cmd(u8 data);
extern void lcd_refresh(void);


#endif

